package cn.ncu.wechat.controller;

import cn.ncu.wechat.service.BannerService;
import cn.ncu.wechat.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/admin/banners")
public class BannerController {

    @Autowired
    private BannerService bannerService;

    @GetMapping("")
    public Result getBannerList(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false, defaultValue = "-1") Integer status
    ) {
        return bannerService.getBannerList(page, pageSize, status);
    }

    @PostMapping("")
    public Result addBanner(@RequestBody Map<String, Object> request) {
        return bannerService.addBanner(request);
    }


    @PutMapping("/{id}")
    public Result updateBanner(@PathVariable Long id, @RequestBody Map<String, Object> request) {
        return bannerService.updateBanner(id, request);
    }

    @DeleteMapping("/{id}")
    public Result deleteBanner(@PathVariable Long id) {
        return bannerService.deleteBanner(id);
    }

    @PostMapping("/sort")
    public Result sortBanner(@RequestBody Map<String, List<Long>> request) {
        return bannerService.sortBanner(request);
    }

    @GetMapping("/{id}/status")
    public Result changeStatus(@PathVariable Long id, @RequestParam Integer status) {
        return bannerService.changeStatus(id, status);
    }

    @DeleteMapping("/batch")
    public Result deleteBanners(@RequestBody Map<String, List<Long>> request) {
        return bannerService.deleteBanners(request);
    }

    @GetMapping("/statistics")
    public Result getStatistics() {
        return bannerService.getStatistics();
    }
}
